package org.springblade.modules.system.controller;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.modules.system.entity.FlowerType;
import org.springblade.modules.system.service.FlowerTypeService;
import org.springblade.utils.PageBounds;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;

@RestController
@RequestMapping("/flowerType")
@AllArgsConstructor
@ApiModel(value = "花卉类型对象")
public class FlowerTypeController {

	FlowerTypeService flowerTypeService;

	//显示列表
	@GetMapping("/showFlowerTypeTable")
	public HashMap<String, Object> showFlowerTypeTable(FlowerType flowerType, int currentPage, int pageSize) {
		HashMap<String, Object> hashMap = new HashMap<>();
		PageBounds<FlowerType> pageBounds = flowerTypeService.showFlowerTypeTable(flowerType, currentPage, pageSize);
		hashMap.put("data", pageBounds);
		return hashMap;
	}

	//根据ID查询类型信息
	@GetMapping("/getFlowerTypeById")
	public Object getFlowerTypeById(Integer fid){
		FlowerType flowerType = flowerTypeService.getFlowerTypeById(fid);
		if(flowerType!=null){
			return flowerType;
		}else{
			return "未找到信息";
		}
	}

	//修改
	@PostMapping("/updateFlowerType")
	public R updateFlowerType(FlowerType flowerType){
		int i = flowerTypeService.updateFlowerType(flowerType);
		return R.status(i>0);
	}

	//添加
	@PostMapping("/addFlowerType")
	public R addFlowerType(FlowerType flowerType){
		int i = flowerTypeService.addFlowerType(flowerType);
		return R.status(i>0);
	}

	//根据id删除
	@PostMapping("/delFlowerType")
	public R delFlowerType(Integer fid){
		int i = flowerTypeService.delFlowerType(fid);
		return R.status(i>0);
	}

	//批量删除
	@PostMapping("/deleteFlowerTypes")
	public R deleteFlowerTypes(Integer[] ids){
		int i = flowerTypeService.deleteFlowerTypes(Arrays.asList(ids));
		return R.status(i>0);
	}

	//判断所属类型是否为空
	@GetMapping("/judgeType")
	public HashMap<String, Object> judgeType(Integer[] fid){
		HashMap<String, Object> map = new HashMap<>();
		int i = flowerTypeService.judgeType(Arrays.asList(fid));
		map.put("num", i);
		return map;
	}

}
